# # import requests
# # import json

# # url_generate = "http://localhost:11434/api/generate"

# # def get_response(url, data):
# #     response = requests.post(url, json=data)
# #     response_dict = json.loads(response.text)
# #     response_content = response_dict["response"]
# #     return response_content

# # data = {
# #     "model": "qwen2.5:14b",
# #     "prompt": "Why is the sky blue?",
# #     "stream": False
# # }

# # res = get_response(url_generate, data)
# # print(res)

# import requests
# import json

# url_generate = "http://localhost:11434/api/generate"

# # def get_response(url, data):
# #     response = requests.post(url, json=data)
# #     response_dict = json.loads(response.text)
# #     response_content = response_dict["response"]
# #     return response_content

# def get_response(url, data):
#     response = requests.post(url, json=data)
#     response_dict = response.json()  # 使用.json()方法直接解析JSON响应

#     print("Key: ", response_dict.keys())
#     print("Actual response from API:", response_dict)  # 打印实际响应内容

#     # 检查'response'键是否存在于响应字典中
#     if 'response' in response_dict:
#         response_content = response_dict["response"]
#     else:
#         print("Key 'response' not found in the response.")
#         response_content = None  # 或者你可以设置一个默认值或者错误信息

#     return response_content

# # 假设你通过RAG获取的信息如下：
# rag_info = [
#     {"title": "人工智能简介", "text": "人工智能（Artificial Intelligence），英文缩写为AI。它是研究、开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门新的技术科学。"},
#     {"title": "人工智能应用", "text": "人工智能的应用包括机器视觉、自然语言处理、专家系统、智能搜索、推理、推荐系统等。"}
# ]

# # 将RAG信息加入到data中
# data = {
#     "model": "qwen2.5:14b",
#     "prompt": "介绍一下人工智能。",
#     "stream": False,
#     "context": rag_info  # 将RAG信息作为上下文加入
# }

# res = get_response(url_generate, data)
# print(res)

TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "get_current_temperature",
            "description": "Get current temperature at a location.",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": 'The location to get the temperature for, in the format "City, State, Country".',
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": 'The unit to return the temperature in. Defaults to "celsius".',
                    },
                },
                "required": ["location"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "get_temperature_date",
            "description": "Get temperature at a location and date.",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": 'The location to get the temperature for, in the format "City, State, Country".',
                    },
                    "date": {
                        "type": "string",
                        "description": 'The date to get the temperature for, in the format "Year-Month-Day".',
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": 'The unit to return the temperature in. Defaults to "celsius".',
                    },
                },
                "required": ["location", "date"],
            },
        },
    },
]
MESSAGES = [
    {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant.\n\nCurrent Date: 2024-09-30"},
    {"role": "user",  "content": "What's the temperature in San Francisco now? How about tomorrow?"},
]


tools = TOOLS
messages = MESSAGES[:]

from openai import OpenAI

# url_generate = "http://localhost:11434/api/generate"
# openai_api_base = "http://localhost:11434/v1"

# sk-c111a1f475d84bc7b8485b0f69c27119
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:11434/v1"

client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)


response = client.chat.completions.create(
    model="qwen2.5:14b",  # 使用的模型名称
    # messages=[
    #     {"role": "system", "content": "You are a helpful assistant."},
    #     {"role": "user", "content": "你是谁"},
    #     {"role": "user", "content": "今天是星期几?"}
    # ]
    messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    # todo : test role = user when rag
    {"role": "system", "content": "Tom joined the company as CEO in 2023."},  # 检索到的背景信息作为系统消息
    {"role": "user", "content": "Who is the CEO of the company?"}  # 用户的问题
]
)
print(response.choices[0].message.content)



# model_name = "Qwen/Qwen2.5-14B-Instruct"


# response = client.chat.completions.create(
#     model=model_name,
#     messages=messages,
#     tools=tools,
#     temperature=0.7,
#     top_p=0.8,
#     max_tokens=512,
#     extra_body={
#         "repetition_penalty": 1.05,
#     },
# )

# messages.append(response.choices[0].message.model_dump())



